//
//  HXNavigationController.swift
//  HXSwift
//
//  Created by apple　　　 on 2016/11/22.
//  Copyright © 2016年 yangguang. All rights reserved.
//

import UIKit

class HXNavigationController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //隐藏标题栏
        navigationBar.isHidden = true

    }
    
    // MARK:重写push方法
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        
        if childViewControllers.count > 0 {
            
            viewController.hidesBottomBarWhenPushed = true
        }
        
        //判断是不是基类控制器
        if let vc = viewController as? HXBaseController {
            
            var title = ""
            
            //判断控制器级数
            if childViewControllers.count == 1 {
                
                
                title = childViewControllers.first?.title ?? "返回"
            }
            
            vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, style: UIBarButtonItemStyle(rawValue: 1)!, target: self, action: #selector(popToParent))
        }
        
        super.pushViewController(viewController, animated: true)
        
    }
    
    //pop上一个控制
    @objc private func popToParent() {
        
        popViewController(animated: true)
    }
}
